package edu.spec.xhd.intent;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import edu.spec.xhd.R;


public class ActivityB extends AppCompatActivity {

    private TextView textViewData;
    private String data = "";
    private Button buttonIntentDataBack;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);
        initViews();
        initListeners();
        Intent i = getIntent();
        data = i.getStringExtra("data");
        textViewData.setText(data);
    }

    private void initViews(){
        textViewData = findViewById(R.id.tv_data);
        buttonIntentDataBack = findViewById(R.id.btn_intent_data_back);
    }

    private void initListeners(){
        buttonIntentDataBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.putExtra("data_return", "SAFE");
                setResult(RESULT_OK, i);
                finish();
            }
        });
    }

}
